# -*- coding: utf-8 -*-
# standard
import os
import sys

# third
from fastapi import APIRouter
from fastapi import Depends
from fastapi import Query as QueryParam
from pydantic import BaseModel

# local
_P_PATH =  os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
if _P_PATH not in sys.path:
    sys.path.append(_P_PATH)
from toolbox.common_tools import logger
from toolbox.common_tools import INCLUDE_SCHEMA
from models.base_model import check_instruction_authorization
from db.sqlalchemy_dbc import Resp
from functions.event_func import *


"""
@Title:   event 模块
@File: event_view.py
@Author: walle 2025年01日01日 10时07分03秒
@Version: 1.0.0
@Desc: 
"""


router = APIRouter(prefix="/v1/event")
EXT = {"tags": ["事件检听"], "response_model": Resp, "include_in_schema": INCLUDE_SCHEMA}


@router.post("/sensor", summary="传感器事件", **EXT)
async def sensor_event_view(
    params: IoTEvent,
    authorization: str = Depends(check_instruction_authorization),
    ):
    logger.debug(f"sensor event: {params.model_dump()}")
    await receive_mic_service_event(params)
    return Resp()


@router.post("/lan_node", summary="内网节点事件", **EXT)
async def lan_node_event_view(
    params: LanEvent,
    authorization: str = Depends(check_instruction_authorization),
    ):
    logger.debug(f"lan node event: {params.model_dump()}")
    await receive_mic_service_event(params)
    return Resp()


@router.post("/gateway_event", summary="zabbix发来的网关事件", **EXT)
async def gateway_event_view(
    params: GatewayEvent,
    authorization: str = Depends(check_instruction_authorization),
    ):
    logger.debug(f"zabbix alert event: {params.model_dump()}")
    await receive_mic_service_event(params)
    return Resp()


if __name__ == '__main__':
    pass